<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>作品老师管理</title>
       <!-- bootstrap -->
    <script src="vendor/jquery/jquery.min.js"></script>
    <link href="vendor/bootstrap/css/bootstrap.min.css"  rel="stylesheet">
    <script src="vendor/bootstrap/js/bootstrap.min.js"></script>

    <!-- 主要css-->
    <link rel="stylesheet" href="css/style.default.css" id="theme-stylesheet">
   
    <!-- vue和axios -->
    <script src="js/vue.min.js"></script>
    <script src="js/axios.min.js"></script>
    
   <!-- js -->
    <script src="js/header.js"></script>
</head>
<body>
    <script>
  
        $(function(){
          if(sessionStorage.jwt != '123456'){
              window.location.href = 'admin_login.html';
            }
          var pid = getUrlParms("pid");
                       var data4Vue = {
                           data2:null,
                           id:0,
                           name:'',
                           tel:'',
                           email:'',
                           
                       };
                       //ViewModel
                      var vue =new Vue({
                            el: '#workArea',
                            data: data4Vue,
                            mounted:function(){ //mounted　表示这个 Vue 对象加载成功了
                            this.init();     
                            },
                            methods: {
                              // 清理数据
                              clear:function () {
                                this.name='';
                                this.tel='';
                                this.email='';
                                },
                              //   //  获取数据
                              get:function (id,pid,name,tel,email) {
                                this.id=id;
                                this.pid=pid;
                                this.name=name;
                                this.tel=tel;
                                this.email=email;
                              },
                              // 分页显示
                                init:function(){
                                  var uri='http://120.79.186.44:9092/manager/production/teacher/selByPid';
                                  var url=uri+"?pid="+pid+"&page="+this.page;
                                 axios.get(url).then(response => {
                            this.data2 = response.data;
                            })    //获取到的indexDatas赋值给data2
                          .catch(function (error) { // 请求失败处理
                            console.log(error);
                            });
                                 },
                                //  删除
                                 deleteBean: function(id) {     
                                  var d = confirm("是否要删除");  
                                  var uri='http://120.79.186.44:9092/manager/production/teacher/delete';
                                  var url=uri+ "?ids="+id;
                                  if(d===true)               
                                   axios.post(url)
                                     .then(res => {
                                      if(res.status === 200) {
                                        alert("删除成功");
                                        this.init();
                                    }
                                    })
                                 },
                                //  更新
                                 update: function() { 
                                  if(!checkEmpty(this.name, "姓名"))
                                   return;
                                  if(!checkEmpty(this.tel, "电话"))
                                   return;
                                  if(!checkEmpty(this.email, "邮箱"))
                                   return;
                                  //验证手机号正确性   
                                  var reg=new RegExp(/^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1}))+\d{8})$/);
                                        if(!reg.test(this.tel)){
                                           alert("手机号填写错误");
                                           return;
                                         }
                                  //电子邮箱判断
                                  var reg2=new RegExp(/^([a-zA-Z0-9._-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/);
                                         if(!reg2.test(this.email)){
                                           alert("电子邮箱填写错误");
                                           return;
                                         }
                                   axios.post('http://120.79.186.44:9092/manager/production/teacher/update',{id:this.id,pid:pid,name:this.name,tel:this.tel,email:this.email})
                                     .then(res => {
                                      if(res.status === 200) {
                                        $('#myModal').modal('hide');
                                        alert("修改成功");
                                        this.init();
                                        this.clear();
                                    }
                                     })
                                 },
                                //  添加
                                 add:function(){
                                  if(!checkEmpty(this.name, "姓名"))
                                   return;
                                  if(!checkEmpty(this.tel, "电话"))
                                   return;
                                  if(!checkEmpty(this.email, "邮箱"))
                                   return;
                                  //验证手机号正确性   
                                  var reg=new RegExp(/^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1}))+\d{8})$/);
                                        if(!reg.test(this.tel)){
                                           alert("手机号填写错误");
                                           return;
                                         }
                                  //电子邮箱判断
                                  var reg2=new RegExp(/^([a-zA-Z0-9._-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/);
                                         if(!reg2.test(this.email)){
                                           alert("电子邮箱填写错误");
                                           return;
                                         }
                                 axios.post('http://120.79.186.44:9092/manager/production/teacher/insert', {pid:pid,name:this.name,tel:this.tel,email:this.email})
                               .then(res => {
                                    if(res.status === 200) {
                                      $('#myModal1').modal('hide');
                                        alert("添加成功");
                                        this.init();
                                        this.clear();
                                    }
                                  })           
                                  },
                                  }
                      });
   
               });
           </script>  
    <div class="page" id="workArea">
        <!--头部-->
        <header class="header">
            <nav class="navbar">
              <div class="container-fluid">
                <div class="navbar-holder d-flex align-items-center justify-content-between">
                  <div class="navbar-header">
                    <a href="#" class="navbar-brand d-none d-sm-inline-block">
                      <div class="brand-text d-none d-lg-inline-block"><span>USC-SE </span><strong>ADMIN</strong></div>
                    </a>
                  </div>

                </div>
              </div>
            </nav>
          </header>
       
        <div class="page-content d-flex align-items-stretch"> 
          
          
          <!-- 左部 -->
          <nav class="side-navbar">
            <!-- 头像名字部分-->
            <div class="sidebar-header d-flex align-items-center">
                <div class="avatar"><img src="img/admin.jpg" alt="..." class="img-fluid rounded-circle"></div>
                <div class="title">
                  <h1 class="h4">USC</h1>
                  <p>Welcome</p>
                </div>
            </div>
  
            <!-- 左边菜单-->
            <span class="heading">管理</span>
            <ul class="list-unstyled">
              <li class="active"><a href="admin_category.html">比赛管理 </a></li>
              <li><a href="admin_user.html">用户管理</a></li>
              <li ><a href="admin_tags.html">标签管理 </a></li>    
              <li ><a href="admin_news.html">近期新闻管理 </a></li>
              <li ><a href="admin_newsswiper.html">新闻轮播图管理 </a></li> 
              <li ><a href="admin_competitionswiper.html">比赛轮播图管理 </a></li>    
            </ul>
          </nav>

          
          <!-- 右部表格部分 -->
          <div class="content-inner"> 
            <!-- 管理标题-->
            <header class="page-header">
              <div class="container-fluid">
                <h2 class="no-margin-bottom">
                    <script>
                        var cname=getUrlParms("cname");
                        document.write(cname)
                        </script>
                  ->
                  <script>
                      var pname=getUrlParms("pname");
                      document.write(pname)
                      </script>
                    ->老师管理</h2>
              </div>
            </header>
            
            <!-- 表格 -->
            <section class="tables">   
              <div class="container-fluid">
                <div class="row">
                  <div class="col-lg-12">
                    <div class="card">
                      <div class="card-body">
                        <div class="table-responsive">  
                          <div>
                          <table class="table table-striped">
                            <thead>
                              <tr>
                      
                                <th>name</th>
                                <th>tel</th>
                                <th>email</th>
                                <th>编辑</th>
                                <th>删除</th>
                              </tr>
                            </thead>
                            <tbody>
                              <tr v-for="bean in data2.data">
                            
                                <td>{{bean.name}}</td>
                                <td>{{bean.tel}}</td>
                                <td>{{bean.email}}</td>
                                <td><a herf="#" @click="get(bean.id,bean.pid,bean.name,bean.tel,bean.email)"><span data-toggle="modal" data-target="#myModal"><img src="img/edit.jpg" width="30" ></span></a></td>
                                <td><a href="#nowhere"  @click="deleteBean(bean.id)"><img src="img/delete.jpg" width="30" ></a></td>
                              </tr>
                            </tbody>
                          </table>
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
            </section>

            <div class="modal fade" id="myModal"  data-backdrop="static" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
              <div class="modal-dialog">
                  <div class="modal-content">
                      <div class="modal-header">
                          <h4 class="modal-title">修改老师信息</h4>
                      </div>
                      <div class="modal-body">
                          <div class="panel-body">
                              <table class="table table-hover" align="center">
                                <tr>
                                  <td>姓名</td>
                                  <td><input    type="text"  v-model="name" class="form-control" placeholder="请在这里输入老师姓名"></td>
                              </tr>
                              <tr>
                                  <td>电话</td>
                                  <td><input   type="text" v-model="tel" class="form-control" placeholder="请在这里输入老师电话"></td>
                              </tr>
                              <tr>
                                <td>电子邮箱</td>
                                <td><input   type="text" v-model="email" class="form-control" placeholder="请在这里输入电子邮箱"></td>
                            </tr>
                              </table>
                          </div>
                      </div>
                      <div class="modal-footer">
                          <button data-dismiss="modal" class="btn btn-default" type="button" @click="clear">关闭</button>
                          <button  class="btn btn-default" type="button" @click="update">提交</button>

                      </div>
                  </div><!-- /.modal-content -->
              </div><!-- /.modal-dialog -->
          </div>

              <!-- 添加模态窗口 -->
           <div align="center">
            <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#myModal1" >
                 添加数据
            </button>
        </div>
        <div class="modal fade" id="myModal1"  data-backdrop="static" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
          <div class="modal-dialog">
              <div class="modal-content">
                  <div class="modal-header">
                      <!-- <button data-dismiss="modal" class="close" type="button"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button> -->
                      <h4 class="modal-title">添加老师信息</h4>
                  </div>
                  <div class="modal-body">
                      <div class="panel-body">
                          <table class="table table-hover" align="center" >
                            <tr>
                              <td>姓名</td>
                              <td><input    type="text"  v-model="name" class="form-control" placeholder="请在这里输入老师姓名"></td>
                          </tr>
                          <tr>
                              <td>电话</td>
                              <td><input   type="text" v-model="tel" class="form-control" placeholder="请在这里输入老师电话"></td>
                          </tr>
                          <tr>
                            <td>电子邮箱</td>
                            <td><input   type="text" v-model="email" class="form-control" placeholder="请在这里输入电子邮箱"></td>
                        </tr>
                          </table>
                      </div>
                  </div>
                  <div class="modal-footer">
                      <button data-dismiss="modal" class="btn btn-default" type="button" >关闭</button>
                      <button  class="btn btn-default" type="button" @click="add">提交</button>
                  </div>
              </div><!-- /.modal-content -->
          </div><!-- /.modal-dialog -->
      </div>


  
  
            <!-- 页脚-->
            <footer class="main-footer">
              <div class="container-fluid">
                <div class="row">
                  <div class="col-sm-6">
                    <p>USC-SE</p>
                  </div>
                  <div class="col-sm-6 text-right">
                    <p>Powered by <a href="https://bootstrapious.com/p/admin-template" class="external">Bootstrapious</a></p>
                </div>
              </div>
            </footer>
  
          </div>
        </div>
      </div>
      
</body>
</html>